import {LIMIT} from '../../store/constant'

function Pagination({currentPage, count, onPageClick, isShowPage}) {

    if (!isShowPage) {
        return null
    }

    // 不用分页
    if (count <= LIMIT) {
        return null
    }


    // 封装页码
    const pageNum = []
    for (let page = 1; page <= Math.ceil(count / LIMIT); page++) {
        pageNum.push(page)
    }

    return (
        <nav>
            <ul>
                {
                    pageNum.map(pageNum => {
                        const isCurrentPage = currentPage === pageNum
                        return (
                            <li
                                key={pageNum}
                                className={isCurrentPage ? "page-item active" : "page-item"}
                            >
                                <span
                                    className="page-link"
                                    onClick={() => {
                                        onPageClick(pageNum)
                                    }}
                                >

                                    {pageNum}
                                </span>
                            </li>
                        )
                    })
                }
            </ul>
        </nav>
    )

}


export default Pagination